package com.nbsaas.boot.shiro3.thread;

import java.util.concurrent.*;

public class App {

    public static void main(String[] args) {

        TenantThreadLocal.setTenant(1L);
        new Thread(()->{
            System.out.println(TenantThreadLocal.getTenant());
            new Thread(()->{
                System.out.println("孙线程:"+TenantThreadLocal.getTenant());
            }).start();

            ExecutorService executorService = Executors.newFixedThreadPool(2);
            Executor contextAwareExecutor = new ContextAwareExecutor(executorService);


            CompletableFuture<Long> data = CompletableFuture.supplyAsync(() -> {
                System.out.println("孙线程1:"+TenantThreadLocal.getTenant());
                return TenantThreadLocal.getTenant();
            },contextAwareExecutor);

            try {
                System.out.println("子线程x:"+data.get());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            }
            executorService.shutdown();
        }).start();;


    }
}
